<!--  -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage" :cell-class-name="cellClassMethod" @selection-change="e => selection = e">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formRef" v-bind="formConfig" @afterSubmitSuccess="reload" />
  </div>
</template>
<script>
import country_select from '@/component/tms/country_select'

import superTablePageFunction from '@/mixin/super-table-page-function';

import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'pms>>transport_goods'

export default {
  title: 'label_transport_goods',
  mixins: [superTablePageFunction, emitOnFunction(emitKey)],
  components: { country_select, },
  data() {
    return {
      selection: [],

      option: {
        //搜索框内容
        search: {
          model: [
            { label: "label_transport_goods", key: "name" },
            { label: "label_status", key: "status", type: 'select', enum: 'IsAvailableStatusEnum', },
          ],
        },
        actionExtra: [
          { label: 'label_base_add', attrs: { type: "primary" }, click: this.clickCreate },
        ],
        table: {
          url: "/oms-api/property/OmsBaseCargoPropertyRpc/selectPage.json",
          model: [
            { type: 'selection', clickToggle: true, },
            { key: 'code', label: 'label_code', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'name', label: 'label_transport_goods', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'priority', label: 'label_priority', 'width': 120, 'show-overflow-tooltip': true, },
            { key: 'status', label: 'label_status', 'width': 120, formatter: (r, c, v, i) => this.$enumShow(v, "IsAvailableStatusEnum") },
            { key: 'remark', label: 'label_remark', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'creator', label: 'label_create_user', 'width': 100, },
            { key: 'gmtCreate', label: 'label_create_time', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
            { key: 'modifier', label: 'label_update_user', 'width': 100, },
            { key: 'gmtModify', label: 'label_update_time', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
            {
              type: 'operate', width: 170, operate: [
                {
                  label: 'label_edit', click: (row) => {
                    this.clickCreate(row)
                  }
                },
                {
                  label: 'label_start_using',
                  type: "confirm-button",
                  url: '/oms-api/property/OmsBaseCargoPropertyRpc/update.json',
                  message: 'label_sure_to_enable_this',
                  buttonClass: "button_text_success",
                  confirmButtonType: 'success',
                  urlType: 'json',
                  if: (row) => row.status == 'DISABLED',
                  params: (row) => {
                    return { ...row, status: 'ENABLE' }
                  }, done: ['tip', 'reload']
                },
                {
                  label: 'label_disable_using',
                  type: "confirm-button",
                  url: '/oms-api/property/OmsBaseCargoPropertyRpc/update.json',
                  message: 'label_tms_confirm_stop',
                  buttonClass: "button_text_danger",
                  confirmButtonType: 'danger',
                  urlType: 'json',
                  if: (row) => row.status == 'ENABLE',
                  params: (row) => {
                    return { ...row, status: 'DISABLED' }
                  }, done: ['tip', 'reload']
                },
                {
                  label: 'label_delete',
                  type: "confirm-button",
                  url: '/oms-api/property/OmsBaseCargoPropertyRpc/delete.json',
                  urlType: 'json',
                  message: 'text_confirm_sure_delete',
                  buttonClass: "button_text_danger",
                  confirmButtonType: 'danger',
                  params: (row) => {
                    return { "id": row["id"] }
                  },
                  done: ['reload', 'tip']
                }
              ],
            }
          ],
        }
      },
      formConfig: {
        customClass: "dialog_auto",
        submitDataHandle: (data) => {
          return data
        },
        form: {
          itemClass: "form_item_default",
          inputClass: "form_input_default",
          // formClass: "form_default_col2 flex_row_wrap",
          default: {},
          model: [
            {
              key: "code",
              label: "label_code",
              disabled: data => !!data.id
            },
            {
              key: "name",
              label: "label_transport_goods",
            },
            {
              key: "priority",
              label: "label_priority",
              min: 0,
              type: 'input-number',
              stepStrictly:true
            },
            {
              key: "remark",
              label: "label_remark",
              attrs: {
                type: 'textarea'
              }
            }
          ],
          rules: {
            code: {
              required: true,
              message: this.$t("tip_can_no_empty"),
              trigger: "blur",
            },
            name: {
              required: true,
              message: this.$t("tip_can_no_empty"),
              trigger: "blur",
            },
            priority: {
              required: true,
              message: this.$t("tip_can_no_empty"),
              trigger: "blur",
            }
          }
        },

      }
    };
  },
  methods: {
    cellClassMethod({ row, column, rowIndex, columnIndex }) {
      if (column.property == 'status') {
        if (row.status == 'ENABLE') {
          return 'color_success'
        } else if (row.status == 'DISABLED') {
          return 'color_danger'
        }
      }
      return ""
    },
    clickCreate(row = {}) {
      const option = {
        title: this.$t('label_transport_goods'),
        submitUrl: row.id ? '/oms-api/property/OmsBaseCargoPropertyRpc/update.json' : '/oms-api/property/OmsBaseCargoPropertyRpc/save.json',
        data: row,
      }
      this["$refs"]["formRef"].showNew(option);
    }
  }
};

</script>
<style></style>
